﻿using System;
using System.Runtime.InteropServices;

namespace BaseSyntax.Expression.Func
{
	public class OptionalParams:ITest
	{
		// 可选参数值限制为常量 字面值等
		public const bool isR = false;
		// isRound是否取整，带默认值，会被视为可选参数
		public float Add(dynamic a, dynamic b, bool isRound = isR)
		{
			if (isRound)
			{
				return (float)(Math.Floor(a) + Math.Floor(b));
			}
			else
			{
				return a + b;
			}
		}
	
		// 使用optional特性，无法显式的定义值
		public float Sub(float a, float b, [Optional] bool isRound, int q = 2)
		{
			if (isRound)
			{
				return (float)(Math.Floor(a) + Math.Floor(b));
			}
			else
			{
				return a + b;
			}
		}
		
		public void Test()
		{
			// a = 3
			float a = Add(1.5f, 1.5f);
			// b = 2
			float b = Add(1.5f, 1.5f, true);
	
			// 可选参数-命名参数
			float c = Sub(1.5f, 1.5f, q:2);
			float d = Sub(1.5f, 1.5f, isRound:true);
			
			Console.WriteLine($"{a},{b},{c},{d}");
		}
	}
}